/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import actionForms.ConnexionForm;
import java.util.HashSet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author alocubiche
 */
public class ConnexionAction extends org.apache.struts.action.Action {
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        
        ConnexionForm f = (ConnexionForm) form;
        f.setLogin(f.getLogin());

        DiscussionBean bean = null;
        ServletContext context = this.getServlet().getServletContext();
        bean = (DiscussionBean)context.getAttribute("discussion");
        if(bean == null)
        {
            bean = new DiscussionBean();
            context.setAttribute("discussion", bean);
        }
        
        bean.getMessages().add(f.getLogin() + " entre dans le salon"); 
        bean.getConnectedUsers().add(f.getLogin());
        
        Ressources.Serialize.set(bean.getMessages());
        
        //TODO : Tester les identifiants
        return (mapping.findForward("success"));
    }
}
